// axios二次封装
import axios from "axios"
// 引入进度条nprogress模块
import nprogress from 'nprogress'
// 引入nprogress模块样式
import '../../node_modules/nprogress/nprogress.css'
import store from '@/store'

const requests = axios.create({
  baseURL: '/mock',
  timeout: 5000,
  headers:{
    token: store.state.registerStore.token,
  }
})


// 请求拦截器
requests.interceptors.request.use((config) => {
  if (store.state.detailStore.uuid_token) {
    // 请求头添加字段
    config.headers.userTempId = store.state.detailStore.uuid_token
  }
  nprogress.start()
  return config
}, (error) => {
  return Promise.reject(error)
})

// 响应拦截器
requests.interceptors.response.use((response) => {
  nprogress.done()
  return response.data
}, (error) => {
  nprogress.done()
  return Promise.reject(error)
})

export default requests